# -*- coding: UTF-8 -*-
import sqlite3
import os

class SqliteDB(object):
    _connectStr=os.path.dirname(__file__)+"/data/sqlite_db.db"
    _con = sqlite3.connect(_connectStr)
    _cur = _con.cursor()

    def update(self,rowid,text):
        sql_str='''update notes set note_text = '{0}' 
        where id= {1} '''.format(text,rowid)
        print(sql_str)
        self._cur.execute(sql_str)
        self._con.commit()
        return self.get_max_rowid()
        # todo self._con.close()

    def get_max_rowid(self):
        self._cur.execute("select max(id) from notes")
        return self._cur.fetchone()[0]
        # todo self._con.close()
    def get_by_rowid(self,rowid):
        self._cur.execute("select * from notes where id=%s"%rowid)
        # print(self._cur.fetchone())
      
        return self._cur.fetchone()
        # todo self._con.close()